The attached patch adds a new dom0_op, DOM0_GETDOMAININFOLIST. This
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 8 Jul 2005 09:06:04 +0000 (09:06 +0000)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 8 Jul 2005 09:06:04 +0000 (09:06 +0000)
operation allows retrieval of the domain info structures for all domains
in one hypercall.

Using a small test program, on a system with 97 domains with
non-contiguous domain IDs, I found that with this hypercall I could
retrieve the full array of info structures 12840 times per second, an
improvement from 2380 times per second with the DOM0_GETDOMAININFO op.

The patch also adds a libxc wrapper for this new hypercall.

Signed-off-by: Josh Triplett <josht@us.ibm.com>
tools/libxc/xc.h
tools/libxc/xc_domain.c
xen/common/dom0_ops.c
xen/include/public/dom0_ops.h

index 12d906abb14fc7cfc75fe8fe08839650304c334a..073f6562c0d6182e48f8539781e874c2871947b6 100644 (file)
@@ -191,6 +191,24 @@ int xc_domain_getinfo(int xc_handle,
                       unsigned int max_doms,
                       xc_dominfo_t *info);
 
+/**
+ * This function will return information about one or more domains, using a
+ * single hypercall.  The domain information will be stored into the supplied
+ * array of xc_domaininfo_t structures.
+ *
+ * @parm xc_handle a handle to an open hypervisor interface
+ * @parm first_domain the first domain to enumerate information from.
+ *                    Domains are currently enumerate in order of creation.
+ * @parm max_domains the number of elements in info
+ * @parm info an array of max_doms size that will contain the information for
+ *            the enumerated domains.
+ * @return the number of domains enumerated or -1 on error
+ */
+int xc_domain_getinfolist(int xc_handle,
+                          u32 first_domain,
+                          unsigned int max_domains,
+                          xc_domaininfo_t *info);
+
 /**
  * This function returns information about one domain.  This information is
  * more detailed than the information from xc_domain_getinfo().
index 5cd6b43e8e809eebf37242fb5cad6d0c300f1ad8..a341bb0bc36064dca397f5159826c284d7885fb1 100644 (file)
@@ -125,6 +125,33 @@ int xc_domain_getinfo(int xc_handle,
     return nr_doms;
 }
 
+int xc_domain_getinfolist(int xc_handle,
+                          u32 first_domain,
+                          unsigned int max_domains,
+                          xc_domaininfo_t *info)
+{
+    int ret = 0;
+    dom0_op_t op;
+
+    if(mlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0)
+        return -1;
+    
+    op.cmd = DOM0_GETDOMAININFOLIST;
+    op.u.getdomaininfolist.first_domain = first_domain;
+    op.u.getdomaininfolist.max_domains  = max_domains;
+    op.u.getdomaininfolist.buffer       = info;
+
+    if(xc_dom0_op(xc_handle, &op) < 0)
+        ret = -1;
+    else
+        ret = op.u.getdomaininfolist.num_domains;
+    
+    if(munlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0)
+        ret = -1;
+    
+    return ret;
+}
+
 int xc_domain_get_vcpu_context(int xc_handle,
                                u32 domid,
                                u32 vcpu,
index 705f27bbb4dbf7455424feb5cd80b3aecdde4460..81a6028446a2875126ed2b3ee4847c8bcfcb7051 100644 (file)
@@ -88,6 +88,60 @@ static int allocate_domid(domid_t *pdom)
     return err;
 }
 
+static void getdomaininfo(struct domain *d, dom0_getdomaininfo_t *info)
+{
+    struct vcpu   *v;
+    u64 cpu_time = 0;
+    int vcpu_count = 0;
+    int flags = DOMFLAGS_PAUSED | DOMFLAGS_BLOCKED;
+    
+    info->domain = d->domain_id;
+    
+    memset(&info->vcpu_to_cpu, -1, sizeof(info->vcpu_to_cpu));
+    memset(&info->cpumap, 0, sizeof(info->cpumap));
+    
+    /* 
+     * - domain is marked as paused or blocked only if all its vcpus 
+     *   are paused or blocked 
+     * - domain is marked as running if any of its vcpus is running
+     * - only map vcpus that aren't down.  Note, at some point we may
+     *   wish to demux the -1 value to indicate down vs. not-ever-booted
+     *   
+     */
+    for_each_vcpu ( d, v ) {
+        /* only map vcpus that are up */
+        if ( !(test_bit(_VCPUF_down, &v->vcpu_flags)) )
+            info->vcpu_to_cpu[v->vcpu_id] = v->processor;
+        info->cpumap[v->vcpu_id] = v->cpumap;
+        if ( !(v->vcpu_flags & VCPUF_ctrl_pause) )
+            flags &= ~DOMFLAGS_PAUSED;
+        if ( !(v->vcpu_flags & VCPUF_blocked) )
+            flags &= ~DOMFLAGS_BLOCKED;
+        if ( v->vcpu_flags & VCPUF_running )
+            flags |= DOMFLAGS_RUNNING;
+        if ( v->cpu_time > cpu_time )
+            cpu_time += v->cpu_time;
+        vcpu_count++;
+    }
+    
+    info->cpu_time = cpu_time;
+    info->n_vcpu = vcpu_count;
+    
+    info->flags = flags |
+        ((d->domain_flags & DOMF_dying)    ? DOMFLAGS_DYING    : 0) |
+        ((d->domain_flags & DOMF_shutdown) ? DOMFLAGS_SHUTDOWN : 0) |
+        d->shutdown_code << DOMFLAGS_SHUTDOWNSHIFT;
+
+    if (d->ssid != NULL)
+        info->ssidref = ((struct acm_ssid_domain *)d->ssid)->ssidref;
+    else    
+        info->ssidref = ACM_DEFAULT_SSID;
+    
+    info->tot_pages         = d->tot_pages;
+    info->max_pages         = d->max_pages;
+    info->shared_info_frame = __pa(d->shared_info) >> PAGE_SHIFT;
+}
+
 long do_dom0_op(dom0_op_t *u_dom0_op)
 {
     long ret = 0;
@@ -306,10 +360,6 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
     case DOM0_GETDOMAININFO:
     { 
         struct domain *d;
-        struct vcpu   *v;
-        u64 cpu_time = 0;
-        int vcpu_count = 0;
-        int flags = DOMFLAGS_PAUSED | DOMFLAGS_BLOCKED;
 
         read_lock(&domlist_lock);
 
@@ -328,59 +378,59 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
 
         read_unlock(&domlist_lock);
 
-        op->u.getdomaininfo.domain = d->domain_id;
+        getdomaininfo(d, &op->u.getdomaininfo);
 
-        memset(&op->u.getdomaininfo.vcpu_to_cpu, -1,
-               sizeof(op->u.getdomaininfo.vcpu_to_cpu));
-        memset(&op->u.getdomaininfo.cpumap, 0,
-               sizeof(op->u.getdomaininfo.cpumap));
+        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )     
+            ret = -EINVAL;
 
-        /* 
-         * - domain is marked as paused or blocked only if all its vcpus 
-         *   are paused or blocked 
-         * - domain is marked as running if any of its vcpus is running
-         * - only map vcpus that aren't down.  Note, at some point we may
-         *   wish to demux the -1 value to indicate down vs. not-ever-booted
-         *   
-         */
-        for_each_vcpu ( d, v ) {
-            /* only map vcpus that are up */
-            if ( !(test_bit(_VCPUF_down, &v->vcpu_flags)) )
-                op->u.getdomaininfo.vcpu_to_cpu[v->vcpu_id] = v->processor;
-            op->u.getdomaininfo.cpumap[v->vcpu_id]      = v->cpumap;
-            if ( !(v->vcpu_flags & VCPUF_ctrl_pause) )
-                flags &= ~DOMFLAGS_PAUSED;
-            if ( !(v->vcpu_flags & VCPUF_blocked) )
-                flags &= ~DOMFLAGS_BLOCKED;
-            if ( v->vcpu_flags & VCPUF_running )
-                flags |= DOMFLAGS_RUNNING;
-            if ( v->cpu_time > cpu_time )
-                cpu_time += v->cpu_time;
-            vcpu_count++;
-        }
+        put_domain(d);
+    }
+    break;
 
-        op->u.getdomaininfo.cpu_time = cpu_time;
-        op->u.getdomaininfo.n_vcpu = vcpu_count;
+    case DOM0_GETDOMAININFOLIST:
+    { 
+        struct domain *d;
+        dom0_getdomaininfo_t info;
+        dom0_getdomaininfo_t *buffer = op->u.getdomaininfolist.buffer;
+        u32 num_domains = 0;
 
-        op->u.getdomaininfo.flags = flags |
-            ((d->domain_flags & DOMF_dying)    ? DOMFLAGS_DYING    : 0) |
-            ((d->domain_flags & DOMF_shutdown) ? DOMFLAGS_SHUTDOWN : 0) |
-            d->shutdown_code << DOMFLAGS_SHUTDOWNSHIFT;
+        read_lock(&domlist_lock);
 
-        if (d->ssid != NULL)
-            op->u.getdomaininfo.ssidref = ((struct acm_ssid_domain *)d->ssid)->ssidref;
-        else    
-            op->u.getdomaininfo.ssidref = ACM_DEFAULT_SSID;
+        for_each_domain ( d )
+        {
+            if ( d->domain_id < op->u.getdomaininfolist.first_domain )
+                continue;
+            if ( num_domains == op->u.getdomaininfolist.max_domains )
+                break;
+            if ( (d == NULL) || !get_domain(d) )
+            {
+                ret = -ESRCH;
+                break;
+            }
 
-        op->u.getdomaininfo.tot_pages   = d->tot_pages;
-        op->u.getdomaininfo.max_pages   = d->max_pages;
-        op->u.getdomaininfo.shared_info_frame = 
-            __pa(d->shared_info) >> PAGE_SHIFT;
+            getdomaininfo(d, &info);
 
-        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )     
-            ret = -EINVAL;
+            put_domain(d);
 
-        put_domain(d);
+            if ( copy_to_user(buffer, &info, sizeof(dom0_getdomaininfo_t)) )
+            {
+                ret = -EINVAL;
+                break;
+            }
+            
+            buffer++;
+            num_domains++;
+        }
+        
+        read_unlock(&domlist_lock);
+        
+        if ( ret != 0 )
+            break;
+        
+        op->u.getdomaininfolist.num_domains = num_domains;
+
+        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )
+            ret = -EINVAL;
     }
     break;
 
index 0c539ea11b48334ca907ba511d71d318703d1275..60e215b09cb367ca24908e88eb027ef700071c88 100644 (file)
@@ -19,7 +19,7 @@
  * This makes sure that old versions of dom0 tools will stop working in a
  * well-defined way (rather than crashing the machine, for instance).
  */
-#define DOM0_INTERFACE_VERSION   0xAAAA100C
+#define DOM0_INTERFACE_VERSION   0xAAAA100D
 
 /************************************************************************/
 
@@ -357,6 +357,16 @@ typedef struct {
     u64     cpu_time;                 
 } dom0_getvcpucontext_t;
 
+#define DOM0_GETDOMAININFOLIST    38
+typedef struct {
+    /* IN variables. */
+    domid_t               first_domain;
+    memory_t              max_domains;
+    dom0_getdomaininfo_t *buffer;
+    /* OUT variables. */
+    memory_t              num_domains;
+} dom0_getdomaininfolist_t;
+
 typedef struct {
     u32 cmd;
     u32 interface_version; /* DOM0_INTERFACE_VERSION */
@@ -389,6 +399,7 @@ typedef struct {
         dom0_microcode_t         microcode;
         dom0_ioport_permission_t ioport_permission;
         dom0_getvcpucontext_t    getvcpucontext;
+        dom0_getdomaininfolist_t getdomaininfolist;
     } u;
 } dom0_op_t;